package com.sphd.emanu.fragment.saleorder;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.sphd.emanu.R;
import com.sphd.emanu.activity.ordersdetail.OrdersdetailActivity;
import com.sphd.emanu.adapter.SaleorderAdapter;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.interfaces.SaleorderFragmentLetter;
import com.sphd.emanu.mvp.MVPBaseFragment;
import com.sphd.emanu.pojo.DaySale;
import com.sphd.emanu.pojo.login.User;
import com.sphd.emanu.pojo.order.Order;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
// TODO: 2017/4/24 销售订单
/**
 * @Author Hu
 * @Time 2017/4/24 -- 16:11.
 * @Email 87683202@qq.com
 */
public class SaleorderFragment extends MVPBaseFragment<SaleorderContract.View, SaleorderPresenter> implements SaleorderContract.View {
    @BindView(R.id.my_recycler)
    RecyclerView myRecycler;
    @BindView(R.id.my_swf)
    SwipeRefreshLayout mySwf;
    Unbinder unbinder;
    SaleorderAdapter saleorderAdapter;
    SaleorderFragmentLetter saleorderFragmentLetter;
    Bundle bundle;
    public void setSaleorderFragmentLetter(SaleorderFragmentLetter saleorderFragmentLetter) {
        this.saleorderFragmentLetter = saleorderFragmentLetter;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.myswf_and_recycler;
    }

    @Override
    protected void initView() {
       bundle=getArguments();
        unbinder = ButterKnife.bind(this, rootView);
        initAdapter();
        saleorderFragmentLetter.readyedSale();
        initEvent();
        setUserVisibleHint(true);
    }
    private void initEvent() {
        mySwf.setOnRefreshListener(()->mySwf.setRefreshing(false));
        myRecycler.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                Order order = (Order) adapter.getItem(position);
                bundle.putSerializable(Constant.ORDER_ENTITY, order);
                Intent intent = new Intent(context, OrdersdetailActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
    @Override
    protected void initData() {

    }


    private void initAdapter() {
        setRefresh(mySwf);
        setRecyWithDecoration(myRecycler);
        saleorderAdapter = new SaleorderAdapter(R.layout.item_sale_order,new ArrayList<Order>());
        saleorderAdapter.setEmptyView(emptyView);
        myRecycler.setAdapter(saleorderAdapter);
    }

  
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    public void setList(List<Order> orderList) {
        saleorderAdapter.setNewData(orderList);
    }
}
